<template>
    <div class="index">
    <div @click="back">返回</div> 
    <div v-for="(itme,index) in tabs" :key="index">{{itme.text}}</div>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    name:'index',
    data(){
        return{
            list:[],
            active:0,
            tabs:[
                {
                    id:0,
                    name:'all',
                    text:'全部'
                },
                {
                    id:1,
                    name:'share',
                    text:'分享'
                },
                {
                    id:2,
                    name:'ask',
                    text:'问答'
                },
                {
                    id:3,
                    name:'job',
                    text:'招聘'
                },
            ]
        }
    },
  methods:{
    back(){
        this.$router.go(-1);//返回上一层
    },
    getlist:function(index,page,limit){
        axios.get('https://cnodejs.org/api/v1/topics',{
            params:{
                page:this.page || 1,
                tab:index,
                limit:this.limit ||20
            }
        }).then((res)=>{
            this.list = []
            const data = res.data
            data.data.map((itme)=>this.list.push(itme))
            console.log(this.list)
        }).catch((error)=>{
            console.log(error)
        })
    }
},
 created () {
    this.getlist()
  }
}
</script>

